cc.Class({
    extends: cc.Component,

    properties: {
       decelSpts: [cc.SpriteFrame],
       jumpSpts: [cc.SpriteFrame],
       fallHeadSpts: [cc.SpriteFrame],
       fallBackSpts: [cc.SpriteFrame]
    },

    onLoad () {
        this.blkSprite = this.node.find('blk_sprite');
        this.blkSprite.parent = null;
    },

    setRoadBlock(data, y) {
        var len = data.times.length;
        var s = 0;
        for(var i = 0; i < len; i++) {
            var blk = this.getBlock(data.states[i]);
            if(blk) {
                var obj = cc.instantiate(this.blkSprite);
                obj.parent = this.node;
                obj.x = s;
                obj.y = y;
                obj.getComponent(cc.Sprite).spriteFrame = blk;
            }
            s += data.moves[i] * GLOBAL.FACTOR_MOVE;
        }
    },

    getBlock(state) {
        var spts = null;
        switch(state) {
            case GLOBAL.STATE_JUMP: spts = this.jumpSpts; break;
            case GLOBAL.STATE_DECEL: spts = this.decelSpts; break;
            case GLOBAL.STATE_FALL_BACK: spts = this.fallBackSpts; break;
            case GLOBAL.STATE_FALL_HEAD: spts = this.fallHeadSpts; break;
            default: return null;
        }
        return spts[Math.rand(0, spts.length - 1)];
    }
});
